import Layout from '@/views/layout/Layout'
import { appRouter } from '@/app/router'
import { generatorRouter } from './menu.router'
// const _importBf = require('./_import_beneform4j')
const _importBf = require('./_import_' + process.env.NODE_ENV)
/**
 * 将生成的菜单配置转为vue 路由配置
 */
generatorRouter.forEach(v => {
  v.component = Layout
})
convertMenusToRouterConfig(generatorRouter)
function convertMenusToRouterConfig(menus) {
  menus.forEach((v) => {
    v.meta = {
      title: v.text,
      icon: v.icon,
      des: v.path,
      depth: v.depth,
      id: v.id,
      leaf: v.leaf,
      permType: v.permType
    }
    delete v['path']
    delete v['icon']
    delete v['depth']
    delete v['leaf']
    delete v['text']
    delete v['permType']
    v.name = v.id
    v.hidden = true
    if (!v.children) {
      v.path = v.id
      if (!v.url) {
        v.hidden = true
        return false
      }
      // const keyArr = v.url.split('/')
      const vueFileName = v.url
      // console.log(vueFileName)
      v.component = _importBf(vueFileName)
      delete v['url']
    } else {
      v.path = '/' + v.id
      if (!v.component) {
        v.component = _importBf('/router-slot')
      }
    }
    v.alwaysShow = true
    // console.log(v)
    if (v.children) {
      convertMenusToRouterConfig(v.children)
    }
  })
}
// console.log(generatorRouter)
export const beneform4jRouter = generatorRouter.concat([
  // {
  //   path: '/system',
  //   component: Layout,
  //   redirect: '/system/index',
  //   alwaysShow: true, // will always show the root menu
  //   meta: {
  //     title: '系统管理',
  //     icon: 'lock',
  //     roles: ['admin', 'editor'] // you can set roles in root nav
  //   },
  //   children: [
  //     {
  //       path: 'index',
  //       component: _importBf('system/user/user'),
  //       name: 'usermanager',
  //       meta: {
  //         icon: 'people',
  //         title: '用户管理',
  //         roles: ['admin'] // or you can only set roles in sub nav
  //       }
  //     }
  //   ]
  // }
]).concat(appRouter)

export const beneform4jLoginRouter = [
  { path: '/login', component: _importBf('/login/index'), hidden: true },
  { path: '/authredirect', component: _importBf('/login/authredirect').default, hidden: true }
]
